<template>
  <div class="container">
    <div class="ibox-content no-border no-padding-bottom">
      <!--搜索栏-->
      <el-col class="toolbar">
        <el-form :inline="true" :model="filterForm" size="mini" label-width="80px" ref="filterForm">
          <el-form-item label="id">
            <el-input v-model="filterForm.id" placeholder="id"></el-input>
          </el-form-item>
          <el-form-item label="用户id">
            <el-input v-model="filterForm.uid" placeholder="精确匹配用户id"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="filterForm.phone" placeholder="精确匹配手机号"></el-input>
          </el-form-item>
          <el-form-item label="客户端">
            <el-select style="width: 178px" v-model="filterForm.client" placeholder="客户端">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.client"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="产品">
            <el-input v-model="filterForm.app_name" placeholder="产品"></el-input>
          </el-form-item>
          <el-form-item label="渠道">
            <el-input v-model="filterForm.channel_name" placeholder="渠道"></el-input>
          </el-form-item>
          <el-form-item label="应用市场">
            <el-select style="width: 178px" v-model="filterForm.market" placeholder="客户端">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.market"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item label="身份证">
            <el-input placeholder="身份证"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-select style="width: 178px" v-model="filterForm.gender" placeholder="性别">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.gender"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="vip">
            <el-select style="width: 178px" v-model="filterForm.s_vip" placeholder="vip">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.vip_status"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="放款时间">
            <el-date-picker
              v-model="chooseTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="chooseDate"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button @click="filterClick" type="primary">查询</el-button>
            <el-button @click="resetFilterForm('filterForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>

    <div class="ibox-content">
      <!--表格-->
      <el-table
        ref="multipleTable"
        :data="arrList"
        size="medium"
        border
        highlight-current-row
        tooltip-effect="dark"
        style="width: 100%"
        :max-height="500"
        v-loading="tableLoading"
      >
        <el-table-column prop="id" label="用户ID" fixed="left"></el-table-column>
        <el-table-column prop="phone" label="手机号"></el-table-column>
        <el-table-column prop="client" label="客户端">
          <template slot-scope="scope">
            <span class="" v-show="scope.row.client==1">iOS</span>
            <span class="" v-show="scope.row.client==2">Android</span>
            <span class="" v-show="scope.row.client!=2 && scope.row.client!=1">--</span>
          </template>
        </el-table-column>
        <el-table-column prop="app_name" label="产品"></el-table-column>
        <el-table-column prop="channel_name" label="渠道"></el-table-column>
        <el-table-column prop="market" label="应用市场"></el-table-column>
        <el-table-column prop="real_name" label="姓名"></el-table-column>
        <el-table-column prop="id_card" label="身份证" width="160"></el-table-column>
        <el-table-column prop="gender" label="性别">
          <template slot-scope="scope">
            <span class="warning" v-show="scope.row.gender==0">未填写</span>
            <span class="" v-show="scope.row.gender==1">男</span>
            <span class="" v-show="scope.row.gender==2">女</span>
          </template>
        </el-table-column>
        <el-table-column prop="is_vip" label="VIP">
          <template slot-scope="scope">
            <span class="warning" v-show="scope.row.is_vip==0">非vip</span>
            <span class="green" v-show="scope.row.is_vip==1">vip</span>
          </template>
        </el-table-column>
        <el-table-column prop="vip_deadline" label="vip到期时间"></el-table-column>
        <el-table-column prop="reviewed_at" label="放款时间" width="160"></el-table-column>
      </el-table>

      <!--分页工具条-->
      <div v-show="arrList.length>0" style="margin-top: 18px;text-align: center">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pageInfo.currPage"
          :page-sizes="[20]"
          :page-size="pageInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageInfo.totalCount">
        </el-pagination>
      </div>

    </div>

  </div>
</template>

<script>
  import {successLoanUserList, userOptions} from "../../api/user";

  export default {
    name: "SuccessLoanUserList",
    data() {
      return {
        arrList: [],
        pageInfo: {
          totalPage: 0,// 总页数
          totalCount: 0,// 总条数
          pageSize: 0,// 每页条数
          currPage: 1// 当前页
        },
        filterForm: {},
        tableLoading: false,
        tableSelectData: [],
        selectOptions: {},
        chooseTime:''
      }
    },
    created() {
      this.getSelectOptions();
      this.initData();
    },
    methods: {
      initData() {
        this.tableLoading = true;
        successLoanUserList({
          page: this.pageInfo.currPage,
          ...this.filterForm
        }).then(res => {
          this.tableLoading = false;
          const {listData, page} = res.data;
          this.arrList = listData;
          this.pageInfo = page
        }).catch(() => {
          this.tableLoading = false
        })
      },
      getSelectOptions() {
        userOptions({}).then(res => {
          this.selectOptions = res.data;
        }).catch(error=>{

        })
      },
      //分页
      handleCurrentChange(val) {
        // console.log(val);
        this.pageInfo.currPage = val;
        this.initData();
      },
      filterClick() {
        this.pageInfo.currPage = 1;
        this.initData();
      },
      //重置
      resetFilterForm(form) {
        this.$refs[form].resetFields();
        this.filterForm = {};
        this.chooseTime = '';
        this.pageInfo.currPage = 1;
        this.initData();
      },
      //选择时间
      chooseDate(val) {
        this.filterForm.start_date = val[0];
        this.filterForm.end_date = val[1];
      }
    }
  }
</script>

<style scoped lang="scss">

</style>
